package com.peihongli.controller;

import com.peihongli.dao.StudentDao;
import com.peihongli.entity.Student;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;
import java.util.Scanner;

public class StudentController {
    public static void main(String[] args) {
        System.out.println("进入学生管理系统，输入用户名");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.next();
        ApplicationContext context = new ClassPathXmlApplicationContext("context-student.xml");
        StudentDao studentDao = (StudentDao) context.getBean("studentDao");
        List<Student> students = studentDao.findAllStudent();
        for (Student u : students){
            if(name.equals(u.getUsername())){
                System.out.println("输入密码");
                String password = scanner.next();
                if(password.equals(u.getPassword())){
                    System.out.println("登陆成功");
                    System.out.println(u.getUsername()+u.getCourse());
                }
            }
        }
    }
}
